package com.giser.testapp.lib.NetWork;

import com.giser.testapp.lib.App.GlobClass;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.giser.testapp.lib.App.GlobClass.apiBaseUrl;

/**
 * Created by Lss on 2017/11/30.
 */

public class ServiceGenerator {
    private static Retrofit.Builder builder =new Retrofit.Builder().baseUrl(GlobClass.apiBaseUrl)
                    .addConverterFactory(GsonConverterFactory.create());

    private static OkHttpClient.Builder httpClient =
            new OkHttpClient.Builder();

    private static Retrofit retrofit =builder.client(httpClient.build()).build();

    public static void changeApiBaseUrl(String newApiBaseUrl) {
        GlobClass.apiBaseUrl=newApiBaseUrl;
        builder = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create())
                .baseUrl(apiBaseUrl);
        retrofit =builder.client(httpClient.build()).build();
    }
    public static <S> S createService(Class<S> serviceClass) {
        return retrofit.create(serviceClass);
    }
}
